package com.example.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;

public class MoviePage extends InternalPage{

    @FindBy(css = "h2")
    public WebElement title;

    @FindBy(xpath = "//div[@class='button']//a[contains(@onclick, './?go=delete')]")
    public WebElement removeLink;

    public boolean isNewMovieAdded(String movieName) {
        return title.getText().equals(movieName);
    }

    public HomePage removeMovie() {
        removeLink.click();
        wait_().until(alertIsPresent()).accept();
        return MyPageFactory.getPage(driver, HomePage.class);
    }

    public boolean isOnThisPage() {
        return removeLink.isDisplayed();
    }

    @Override
    void tryToOpen() {
        MyPageFactory.getPage(driver, AddMoviePage.class).addNewMovie();
    }
}
